package org.example.backend.demos.web.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> implements Serializable {
    private int code;
    private String msg;
    private T data;


    // 带数据的返回成功的结果
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setMsg("成功");
        result.setData(data);
        result.setCode(200);
        return result;
    }

    // 返回错误的结果
    public static <T> Result error(T data) {
        Result<T> result = new Result<>();
        result.setMsg("失败");
        result.setData(data);
        result.setCode(401);
        return result;
    }


}
